package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.CommunityDao;
import cn.topevery.garden.entity.po.Community;
import cn.topevery.garden.entity.query.CommunityQuery;
import cn.topevery.garden.entity.vo.CommunityVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 群落表
 *
 * @author code-generate
 * @date 2022-01-05
 */
@Repository
public class CommunityDaoImpl extends BaseDaoImpl<Community> implements CommunityDao {
    @Override
    public <P extends DbCsp> List<Community> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<CommunityVO> listPage(CommunityQuery query) {
        String table = "t_community tc";

        String columns = "tc.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tc.c_id desc");
        sqlQueryMate
                .where(true, "tc.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(!StringUtils.isBlank(query.getCode()), "tc.c_code", ScriptConditionEnum.Eq, query.getCode())

        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, CommunityVO.class);
    }

    @Override
    public Community getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }

    @Override
    public List<Community> getList() {
        return null;
    }

    @Override
    public List<Map<String, Object>> listMaps() {
        return getMap("select c_code from t_community where c_db_status = 0");
    }
}
